﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Objects;
using System.Web.Security;

public partial class Admin_CategoryItem : System.Web.UI.Page
{
    protected void LogoutButton_Click(object sender, EventArgs e)
    {
        Session.Abandon();
        FormsAuthentication.SignOut();
        Response.Redirect("~/Default.aspx");
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void CategoryItemFormView_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName.ToUpper() == "CANCEL")
            CategoryItemFormView.ChangeMode(FormViewMode.Insert);
    }
    protected void CategoryItemGridView_SelectedIndexChanged(object sender, EventArgs e)
    {
        CategoryItemFormView.PageIndex = (CategoryItemGridView.PageSize * CategoryItemGridView.PageIndex) + CategoryItemGridView.SelectedIndex;
        CategoryItemFormView.ChangeMode(FormViewMode.Edit);
        CategoryItemGridView.DataBind();
        CategoryItemGridView.SelectedIndex = -1;
    }
    protected void ClearImageButton_Click(object sender, ImageClickEventArgs e)
    {
        CategoryTextBox.Text = string.Empty;
        ClearImageButton.OnClientClick = "return false;";
    }
    protected void SearchImageButton_Click(object sender, ImageClickEventArgs e)
    {
        CategoryItemGridView.PageSize = (PageSizeDropDownList.SelectedIndex == -1 || PageSizeDropDownList.SelectedValue == "0" ? 5 : Convert.ToInt32(PageSizeDropDownList.SelectedValue));
        if (CategoryTextBox.Text != string.Empty)
            ClearImageButton.OnClientClick = string.Empty;
        else
            ClearImageButton_Click(sender, e);
    }
    protected void CategoryItemEntityDataSource_Command(object sender, EntityDataSourceChangedEventArgs e)
    {
        CategoryItemGridView.DataBind();
        CategoryItemFormView.ChangeMode(FormViewMode.Insert);
    }
    protected void CategoryGridView_SelectedIndexChanged(object sender, EventArgs e)
    {
        CategoryLabel.Text = string.Format("{0}", CategoryGridView.Rows[CategoryGridView.SelectedIndex].Cells[2].Text);
        CategoryIDHiddenField.Value = CategoryGridView.SelectedValue.ToString();
        MultiView.SetActiveView(EditView);
    }
    protected void InsertButton_Click(object sender, ImageClickEventArgs e)
    {
        ((HiddenField)CategoryItemFormView.FindControl("CategoryIDHiddenField")).Value = CategoryIDHiddenField.Value;
    }
    protected void ReturnLinkButton_Click(object sender, EventArgs e)
    {
        MultiView.SetActiveView(ShowView);
    }
}


